//
//  shopCategory.swift
//  WxToutiao
//
//  Created by YQ05 on 2018/4/8.
//  Copyright © 2018年 yons. All rights reserved.
//

import Foundation
import ObjectMapper
import Moya

//struct shopCategoryResponse: Mappable{
////    var status : String!
////    var count : Int!
//    var products : [Products]!
//    
//    
//    init?(map: Map) {
//        
//    }
//    mutating func mapping(map: Map) {
////        status <- map["status"]
////        count <- map["count"]
//        products <- map["products"]
//    }
//}
//
//struct Products: Mappable{
//    var ID : Int!
//    var name : String!
//    var price : String!
//    
//    var regprice : String!
//    var desc : String!
//    var img : [Any]?
//    var image : String!
//    
//    init?(map: Map) {
//        
//    }
//    mutating func mapping(map: Map) {
//        ID <- map["ID"]
//        name <- map["name"]
//        price <- map["price"]
//        regprice <- map["regprice"]
//        desc <- map["desc"]
//        img <- map["image"]
//        image = img![0] as! String
//    }
//}
//
//func getshopList(id: Int){
//    let provider = MoyaProvider<NetworkService2>()
//    provider.request(.showCatcodeList(id:id)) { (result) in
//        switch result {
//        case let .success(moyaResponse):
//            let json = try! moyaResponse.mapJSON() as! [String:Any]
//            if let jsonResponse = shopCategoryResponse(JSON: json){
//                print(jsonResponse.products)
//            }
//            
//            
//        case .failure:
//            print("wangluocuowu2")
//            
//        }
//    }
//}
//
//extension Products{
//    
//    //获取产品分类列表
//    static func request(id: Int,completion:@escaping ([Products]?) -> Void){
//        
//        let provider = MoyaProvider<NetworkService2>()
//        provider.request(.showCatcodeList(id: id)) { result in
//            switch result {
//            case let .success(moyaResponse):
//                let json = try! moyaResponse.mapJSON() as! [String:Any]
//                
//                if let shopjsonResponse = shopCategoryResponse(JSON: json){
//                    //print("获取到的产品分类z\(shopjsonResponse.products)")
//                    
//                    completion(shopjsonResponse.products)
//                  
//                    
//                }
//            // do something with the response data or statusCode
//            case  .failure:
//                print("网络错误")
//                completion(nil)
//                // this means there was a network failure - either the request
//                // wasn't sent (connectivity), or no response was received (server
//                // timed out).  If the server responds with a 4xx or 5xx error, that
//                // will be sent as a ".success"-ful response.
//            }
//        }
//        
//    }
//}

